using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Crossborder.Common.RedisModule
{
    public partial class RedisWorker : IRedisWorker
    {
        public RedisCore RedisCore { get; }

        public RedisWorker(RedisCore redisCore)
        {
            RedisCore = redisCore;
        }

        // /// <summary>
        // /// 通过Scan获取所有适配的key
        // /// </summary>
        // /// <param name="key"></param>
        // /// <returns></returns>
        // public List<string> GetKeys(string key)
        // {
        //     List<string> keys = new();
        //     var eps = RedisCore._Conn.GetEndPoints();
        //     var ep = eps[0];
        //     var server = RedisCore._Conn.GetServer(ep);
        //     var keylst = server.Keys(0, key).ToList();
        //     keylst.ForEach(k =>
        //     {
        //         keys.Add(k.ToString());
        //     });
        //     return keys;
        // }

        /// <summary>
        /// 删除Key
        /// </summary>
        /// <param name="key"></param>
        public void RemoveKeys(string key)
        {
            RedisCore.db.KeyDelete(key);
        }

        /// <summary>
        /// 删除Key
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public async Task RemoveKeysAsync(string key)
        {
            await RedisCore.db.KeyDeleteAsync(key);
        }
    }
}